﻿Imports System.Data.OleDb

Public Class Profile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.Params("FanName") = User.Identity.Name Then
            btn_editProfile.Visible = True
        Else
            btn_editProfile.Visible = False
        End If

        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("godzillaFilms").ConnectionString)
        If User.IsInRole("Mothra") Then
            Dim sql = "SELECT * FROM totalComments WHERE Author=@f1"
            Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
            conn.Open()
            cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
            cmd.ExecuteNonQuery()
            Dim dr As OleDbDataReader = cmd.ExecuteReader()
            dr.Read()
            If dr.HasRows Then
                If dr("total") >= 6 Then
                    Roles.AddUserToRole(User.Identity.Name, "King Ghidorah")
                    Roles.RemoveUserFromRole(User.Identity.Name, "Mothra")
                    Dim sqlUp = "UPDATE Profile SET Rank=@f1 WHERE FanName=@f2"
                    Dim cmdUp As OleDbCommand = New OleDbCommand(sqlUp, conn)
                    cmdUp.Parameters.AddWithValue("@f1", "King Ghidorah")
                    cmdUp.Parameters.AddWithValue("@f2", User.Identity.Name)
                    cmdUp.ExecuteNonQuery()
                End If
            End If
            conn.Close()
        End If

        If User.IsInRole("King Ghidorah") Then
            Dim sql = "SELECT * FROM totalReleaseUploads WHERE Uploader=@f1"
            Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
            conn.Open()
            cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
            cmd.ExecuteNonQuery()
            Dim dr As OleDbDataReader = cmd.ExecuteReader()
            dr.Read()
            If dr.HasRows Then
                If dr("totalUploads") >= 2 Then
                    Roles.AddUserToRole(User.Identity.Name, "Godzilla")
                    Roles.RemoveUserFromRole(User.Identity.Name, "King Ghidorah")
                    Dim sqlUp = "UPDATE Profile SET Rank=@f1 WHERE FanName=@f2"
                    Dim cmdUp As OleDbCommand = New OleDbCommand(sqlUp, conn)
                    cmdUp.Parameters.AddWithValue("@f1", "Godzilla")
                    cmdUp.Parameters.AddWithValue("@f2", User.Identity.Name)
                    cmdUp.ExecuteNonQuery()
                End If
            End If
            conn.Close()
        End If
    End Sub

    Protected Sub btn_editProfile_Click(sender As Object, e As EventArgs) Handles btn_editProfile.Click

    End Sub
End Class